<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  
  <title>【Linux】系统学习Crontab定时任务 | 程序小工  | Just do it!</title>
  <meta name="description" content="遇见更好的自己~" />
  <meta name="keywords" content="" />
  <meta name="HandheldFriendly" content="True" />
  <meta name="apple-mobile-web-app-capable" content="yes">
  <link rel="shortcut icon" href="/">
  <link rel="alternate" href="/atom.xml" title="程序小工  | Just do it!">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="crontab 是一个用于设置周期性执行任务的工具。目前服务器端的运行环境大多数为 Linux，在日常的运营和维护中会有很多需要定期执行的操作，其中有些操作是可以机械的定期执行的操作，所以我们可以使用 crontab 定时服务来设置定时任务，从而减少手动操作的任务，帮助提高工作效率。">
<meta name="keywords" content="crontab">
<meta property="og:type" content="article">
<meta property="og:title" content="【Linux】系统学习Crontab定时任务">
<meta property="og:url" content="http://blog.i2arch.tech/2018/07/06/linux-crontab/index.html">
<meta property="og:site_name" content="程序小工  | Just do it!">
<meta property="og:description" content="crontab 是一个用于设置周期性执行任务的工具。目前服务器端的运行环境大多数为 Linux，在日常的运营和维护中会有很多需要定期执行的操作，其中有些操作是可以机械的定期执行的操作，所以我们可以使用 crontab 定时服务来设置定时任务，从而减少手动操作的任务，帮助提高工作效率。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-08-14T07:54:04.832Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【Linux】系统学习Crontab定时任务">
<meta name="twitter:description" content="crontab 是一个用于设置周期性执行任务的工具。目前服务器端的运行环境大多数为 Linux，在日常的运营和维护中会有很多需要定期执行的操作，其中有些操作是可以机械的定期执行的操作，所以我们可以使用 crontab 定时服务来设置定时任务，从而减少手动操作的任务，帮助提高工作效率。">
    
  <link href="https://fonts.googleapis.com/css?family=Inconsolata|Titillium+Web" rel="stylesheet">
  <link href="https://fonts.googleapis.com/css?family=Roboto+Mono" rel="stylesheet">
  <link href='//cdn.bootcss.com/node-waves/0.7.5/waves.min.css' rel='stylesheet'>
  <link rel="stylesheet" href="/style.css">
  <script>
    function setLoadingBarProgress(num) {
      document.getElementById('loading-bar').style.width=num+"%";
    }
  </script>
</head>

<body>
  <div id="loading-bar-wrapper">
  <div id="loading-bar"></div>
</div>


  <script>setLoadingBarProgress(20)</script>
  <header class="l_header">
	<div class='wrapper'>
		<div class="nav-main container container--flex">
			<a class="logo flat-box" href='/' >
				程序小工  | Just do it!
			</a>
			<div class='menu'>
				<ul class='h-list'>
					
						<li>
							<a class='flat-box nav-home' href='/'>
								<i class='icon icon-list2'></i>
								首页
							</a>
						</li>
					
						<li>
							<a class='flat-box nav-archives' href='/archives'>
								<i class='icon icon-bookmark'></i>
								归档
							</a>
						</li>
					
						<li>
							<a class='flat-box nav-about' href='/about'>
								<i class='icon icon-user'></i>
								关于
							</a>
						</li>
					
				</ul>
				<div class='underline'></div>
			</div>
			
				<div class="m_search">
					<form name="searchform" class="form u-search-form">
						<input type="text" class="input u-search-input" placeholder="Search" />
						<span class="icon icon-search"></span>
					</form>
				</div>
			
			<ul class='switcher h-list'>
				
					<li class='s-search'><a href='javascript:void(0)'><span class="icon icon-search flat-box"></span></a></li>
				
				<li class='s-menu'><a href='javascript:void(0)'><span class="icon icon-menu flat-box"></span></a></li>
			</ul>
		</div>

		<div class='nav-sub container container--flex'>
			<a class="logo" class="flat-box" href='javascript:void(0)'>
				Word of Forks
			</a>

			<ul class='switcher h-list'>
				<li class='s-comment'><a href='javascript:void(0)'><span class="icon icon-chat_bubble_outline flat-box"></span></a></li>
				<li class='s-top'><a href='javascript:void(0)'><span class="icon icon-arrow_upward flat-box"></span></a></li>
				<li class='s-toc'><a href='javascript:void(0)'><span class="icon icon-format_list_numbered flat-box"></span></a></li>
			</ul>
		</div>
	</div>
</header>
<aside class="menu-phone">
	<nav>
		
			<a href="/" class="nav-home nav">
				首页
			</a>
		
			<a href="/archives" class="nav-archives nav">
				归档
			</a>
		
			<a href="/about" class="nav-about nav">
				关于
			</a>
		
	</nav>
</aside>

    <script>setLoadingBarProgress(40);</script>
  <div class="l_body">
    <div class='container clearfix'>
      <!-- 左侧内容 -->
      <div class='l_main'>
        <article id="post-linux-crontab"
  class="post white-box article-type-post"
  itemscope itemprop="blogPost">
	<section class='meta'>

	<h2 class="title">
  	<a href="/2018/07/06/linux-crontab/">
    	【Linux】系统学习Crontab定时任务
    </a>
	</h2>

	<div class="pagenav">
		<time>
			2018-07-06
		</time>

		
    
    <div class='cats'>
        <i class="icon icon-bookmark"></i>
        <a href="/categories/Linux/">Linux</a>
    </div>


		
			<div class="pagetags">
				<i class="icon icon-price-tag" style="margin-right: 2px;"></i>
				
					<a href="/tags/crontab/" style="margin-left: 3px;">
						crontab
					</a>
				
			</div>
			
	</div>
	</section>

	
	<section class="toc-wrapper"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#一-cron-定时任务"><span class="toc-text"> 一、cron 定时任务</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1安装-crond-服务和-crontab-工具"><span class="toc-text"> 1.安装 crond 服务和 crontab 工具</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1相关命令"><span class="toc-text"> (1)相关命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2验证-crond-服务"><span class="toc-text"> (2)验证 crond 服务</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#二-crontab-架构"><span class="toc-text"> 二、crontab 架构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1执行步骤"><span class="toc-text"> 1.执行步骤</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2contab-配置文件格式"><span class="toc-text"> 2.contab 配置文件格式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3crontab-配置文件"><span class="toc-text"> 3.crontab 配置文件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1系统配置文件"><span class="toc-text"> (1)系统配置文件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2系统用户-crontab-配置文件保存目录crontab-e-所编辑的文件"><span class="toc-text"> (2)系统用户 crontab 配置文件保存目录[crontab -e 所编辑的文件]</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4crontab-环境变量"><span class="toc-text"> 4.Crontab 环境变量</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1添加-path-到etccrontab"><span class="toc-text"> (1)添加 PATH 到/etc/crontab</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2在执行具体任务前引入系统用户环境变量"><span class="toc-text"> (2)在执行具体任务前引入系统/用户环境变量</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3操作步骤"><span class="toc-text"> (3)操作步骤</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1添加环境变量"><span class="toc-text"> 1)添加环境变量</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2完成执行脚本"><span class="toc-text"> 2)完成执行脚本</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3设置定时任务"><span class="toc-text"> 3)设置定时任务</span></a></li></ol></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#三-实战"><span class="toc-text"> 三、实战</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#1crontab-日志"><span class="toc-text"> 1.crontab 日志</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1cron-日志保存在varlogcron文件中"><span class="toc-text"> (1)cron 日志保存在/var/log/cron文件中</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2清理系统日志"><span class="toc-text"> 2.清理系统日志</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1系统日志的存放位置-varlogmessages"><span class="toc-text"> (1)系统日志的存放位置： /var/log/messages</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2同时清理多个日志文件使用脚本文件"><span class="toc-text"> (2)同时清理多个日志文件[使用脚本文件]</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-文件rootlog_cleansh"><span class="toc-text"> 1). 文件：/root/log_clean.sh</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-定时任务"><span class="toc-text"> 2). 定时任务</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3crontab-备份-source-code"><span class="toc-text"> 3.crontab 备份 source code</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1准备工作"><span class="toc-text"> (1)准备工作</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2编写执行备份的脚本文件datascriptwww_backupsh"><span class="toc-text"> (2)编写执行备份的脚本文件[/data/script/www_backup.sh]</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3脚本解释说明"><span class="toc-text"> (3)脚本解释说明</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-basedir-databackup"><span class="toc-text"> 1). basedir = /data/backup</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-date-f_hm"><span class="toc-text"> 2). $(date +%F_%H%M)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-www_src-basedirwww_srcdate-f_hm"><span class="toc-text"> 3). www_src = $basedir/www_src/$(date +%F_%H%M)</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-d-www_src"><span class="toc-text"> 4). [ ! -d &quot;$www_src&quot; ]</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#5-tar-jpcf-www_srcwwwtarbz2-www"><span class="toc-text"> 5). tar -jpcf $www_src/www.tar.bz2 www</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4创建定时任务"><span class="toc-text"> (4)创建定时任务</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5重启定时任务使其生效"><span class="toc-text"> (5)重启定时任务使其生效</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6查看备份文件大小被备份的原目录是-wordpress-系统"><span class="toc-text"> (6)查看备份文件大小[被备份的原目录是 wordpress 系统]</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4crontab-在-iptables-上的应用"><span class="toc-text"> 4.crontab 在 iptables 上的应用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1应用场景"><span class="toc-text"> (1)应用场景：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2解决之道"><span class="toc-text"> (2)解决之道：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3iptables-简介"><span class="toc-text"> (3)iptables 简介：</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4准备工作"><span class="toc-text"> (4)准备工作</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5设置网络访问黑名单文件datascriptblacklisttxt"><span class="toc-text"> (5)设置网络访问黑名单文件/data/script/blacklist.txt</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#6脚本实现datascriptfirewallsh"><span class="toc-text"> (6)脚本实现[/data/script/firewall.sh]</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#7脚本解释说明"><span class="toc-text"> (7)脚本解释说明</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#1-iptables-f"><span class="toc-text"> 1). iptables -F</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#2-for-line-in-cat-listdo"><span class="toc-text"> 2). for line in cat $list;do</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#3-iptables-i-input-sline-j-drop"><span class="toc-text"> 3). iptables -I INPUT -s$line -j DROP</span></a></li><li class="toc-item toc-level-5"><a class="toc-link" href="#4-echo-line-is-dropped-into-blacklist"><span class="toc-text"> 4). echo &quot;$line is dropped into blacklist&quot;</span></a></li></ol></li><li class="toc-item toc-level-4"><a class="toc-link" href="#8创建定时任务"><span class="toc-text"> (8)创建定时任务</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9查看-iptables-拒绝访问主机的-ip-列表"><span class="toc-text"> (9)查看 iptables 拒绝访问主机的 ip 列表</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#5crontab-在-jenkins-上的扩展"><span class="toc-text"> 5.crontab 在 Jenkins 上的扩展</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#1jenkins-介绍"><span class="toc-text"> (1)Jenkins 介绍</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2使用前提"><span class="toc-text"> (2)使用前提</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#3编辑-jenkins-的启动配置文件etcinitdjenkins"><span class="toc-text"> (3)编辑 jenkins 的启动配置文件[/etc/init.d/jenkins]</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#4相关命令"><span class="toc-text"> (4)相关命令</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#5在-web-网页中进行配置并使用-jenkins"><span class="toc-text"> (5)在 web 网页中进行配置并使用 jenkins</span></a></li></ol></li></ol></li></ol></section>
	

	<section class="article typo">
		<div class="article-entry" itemprop="articleBody">
				<span class="zhaiyao">[摘要]</span>
			<p>crontab 是一个用于设置周期性执行任务的工具。目前服务器端的运行环境大多数为 Linux，在日常的运营和维护中会有很多需要定期执行的操作，其中有些操作是可以机械的定期执行的操作，所以我们可以使用 crontab 定时服务来设置定时任务，从而减少手动操作的任务，帮助提高工作效率。</p>
<a id="more"></a>
<h2 id="一-cron-定时任务"><a class="markdownIt-Anchor" href="#一-cron-定时任务"></a> 一、cron 定时任务</h2>
<h3 id="1安装-crond-服务和-crontab-工具"><a class="markdownIt-Anchor" href="#1安装-crond-服务和-crontab-工具"></a> 1.安装 crond 服务和 crontab 工具</h3>
<h4 id="1相关命令"><a class="markdownIt-Anchor" href="#1相关命令"></a> (1)相关命令</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 清除yum缓存</span></span><br><span class="line">yum clean all</span><br><span class="line"></span><br><span class="line"><span class="comment"># 更新系统的安装包到最新版本</span></span><br><span class="line">yum update</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装cron服务和crontab工具[-y表示yes,没有的话需要手动输入yes]</span></span><br><span class="line">yum install -y cronie crontabs</span><br></pre></td></tr></table></figure>
<h4 id="2验证-crond-服务"><a class="markdownIt-Anchor" href="#2验证-crond-服务"></a> (2)验证 crond 服务</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 检查cond服务是否安装及启动：</span></span><br><span class="line">yum list cronie &amp;&amp; systemctl status crond</span><br><span class="line"></span><br><span class="line"><span class="comment"># 检查crontab工具是否安装：</span></span><br><span class="line">yum list crontabs &amp;&amp; <span class="built_in">which</span> crontab &amp;&amp; crontab -l</span><br></pre></td></tr></table></figure>
<h2 id="二-crontab-架构"><a class="markdownIt-Anchor" href="#二-crontab-架构"></a> 二、crontab 架构</h2>
<h3 id="1执行步骤"><a class="markdownIt-Anchor" href="#1执行步骤"></a> 1.执行步骤</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1.新建|编辑定时任务</span></span><br><span class="line">crontab -e</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2.查看定时任务列表[当前用户(root)保存的计划任务]</span></span><br><span class="line">crontab -l</span><br><span class="line"><span class="comment">#或</span></span><br><span class="line">cat /var/spool/cron/root</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.重启crond进程</span></span><br><span class="line">systemctl restart crond</span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.查看crond状态</span></span><br><span class="line">systemctl status crond</span><br></pre></td></tr></table></figure>
<h3 id="2contab-配置文件格式"><a class="markdownIt-Anchor" href="#2contab-配置文件格式"></a> 2.contab 配置文件格式</h3>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">*     *     *    *    *   [username]   my <span class="built_in">command</span></span><br><span class="line">分    时    日   月   周   [执行用户名]  要运行的命令</span><br><span class="line">0-59 0-23 1-31 1-12  0-6</span><br></pre></td></tr></table></figure>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">* 取值范围内的所有数字</span><br><span class="line">/ 每</span><br><span class="line">- 某个区间</span><br><span class="line">, 几个数的集合</span><br></pre></td></tr></table></figure>
<h3 id="3crontab-配置文件"><a class="markdownIt-Anchor" href="#3crontab-配置文件"></a> 3.crontab 配置文件</h3>
<h4 id="1系统配置文件"><a class="markdownIt-Anchor" href="#1系统配置文件"></a> (1)系统配置文件</h4>
<p><code>/etc/crontab</code></p>
<h4 id="2系统用户-crontab-配置文件保存目录crontab-e-所编辑的文件"><a class="markdownIt-Anchor" href="#2系统用户-crontab-配置文件保存目录crontab-e-所编辑的文件"></a> (2)系统用户 crontab 配置文件保存目录[crontab -e 所编辑的文件]</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">/var/spllo/cron/[目录]</span><br><span class="line">root:/var/spppl/cron/root[文件]</span><br><span class="line">user01:/var/spppl/cron/user01[文件]</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 创建用户</span></span><br><span class="line">useradd user01</span><br><span class="line"><span class="comment"># 使用指定用户登陆系统</span></span><br><span class="line">su - user01</span><br></pre></td></tr></table></figure>
<h3 id="4crontab-环境变量"><a class="markdownIt-Anchor" href="#4crontab-环境变量"></a> 4.Crontab 环境变量</h3>
<h4 id="1添加-path-到etccrontab"><a class="markdownIt-Anchor" href="#1添加-path-到etccrontab"></a> (1)添加 PATH 到/etc/crontab</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/<span class="built_in">local</span>/jdk1.8.0_111/bin</span><br><span class="line"><span class="comment"># 可以直接在定时任务文件使用java程序</span></span><br></pre></td></tr></table></figure>
<h4 id="2在执行具体任务前引入系统用户环境变量"><a class="markdownIt-Anchor" href="#2在执行具体任务前引入系统用户环境变量"></a> (2)在执行具体任务前引入系统/用户环境变量</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># [系统级别环境变量]</span></span><br><span class="line">30 2 * * * <span class="built_in">source</span> /etc/profile;sh /root/test.sh</span><br><span class="line"></span><br><span class="line"><span class="comment"># [用户级别环境变量]</span></span><br><span class="line">30 2 * * * <span class="built_in">source</span> ~/.bash_profile;sh /root/test.sh</span><br></pre></td></tr></table></figure>
<h4 id="3操作步骤"><a class="markdownIt-Anchor" href="#3操作步骤"></a> (3)操作步骤</h4>
<h5 id="1添加环境变量"><a class="markdownIt-Anchor" href="#1添加环境变量"></a> 1)添加环境变量</h5>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># /etc/profile 或者 /root/.bash_profile</span></span><br><span class="line"><span class="attr">PATH</span>=<span class="variable">$PATH</span>:/usr/local/jdk1.<span class="number">8.0</span>_111/bin</span><br><span class="line">export PATH</span><br></pre></td></tr></table></figure>
<h5 id="2完成执行脚本"><a class="markdownIt-Anchor" href="#2完成执行脚本"></a> 2)完成执行脚本</h5>
<figure class="highlight"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># /root/test.sh</span></span><br><span class="line">java -version 2&gt; /root/script.out</span><br></pre></td></tr></table></figure>
<h5 id="3设置定时任务"><a class="markdownIt-Anchor" href="#3设置定时任务"></a> 3)设置定时任务</h5>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 先使/etc/profile生效[添加环境变量]，后使用sh执行脚本文件</span></span><br><span class="line">* * * * * <span class="built_in">source</span> /etc/profile;sh /root/test.sh</span><br><span class="line">* * * * * <span class="built_in">source</span> /root/.bash_profile;sh /root/test.sh</span><br></pre></td></tr></table></figure>
<h2 id="三-实战"><a class="markdownIt-Anchor" href="#三-实战"></a> 三、实战</h2>
<h3 id="1crontab-日志"><a class="markdownIt-Anchor" href="#1crontab-日志"></a> 1.crontab 日志</h3>
<h4 id="1cron-日志保存在varlogcron文件中"><a class="markdownIt-Anchor" href="#1cron-日志保存在varlogcron文件中"></a> (1)cron 日志保存在<code>/var/log/cron</code>文件中</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看最近的两条cron日志</span></span><br><span class="line">tail -n 2 /var/<span class="built_in">log</span>/cron</span><br></pre></td></tr></table></figure>
<h3 id="2清理系统日志"><a class="markdownIt-Anchor" href="#2清理系统日志"></a> 2.清理系统日志</h3>
<h4 id="1系统日志的存放位置-varlogmessages"><a class="markdownIt-Anchor" href="#1系统日志的存放位置-varlogmessages"></a> (1)系统日志的存放位置： <code>/var/log/messages</code></h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"># /var/log目录下日志[平时主要用到的日志文件]</span><br><span class="line">cron -- 定时任务日志</span><br><span class="line">secure -- 相关ssh服务日志</span><br><span class="line">messages -- 系统总日志</span><br><span class="line">firewalld -- 系统防火墙日志</span><br><span class="line">lastlog -- 登录日志</span><br></pre></td></tr></table></figure>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看当前目录下所有文件的大小</span></span><br><span class="line">du -sh .</span><br><span class="line"></span><br><span class="line"><span class="comment"># 清空系统日志 [/dev/null代表一个空文件]</span></span><br><span class="line">* 1 * * * cat /dev/null &gt; /var/<span class="built_in">log</span>/messages</span><br></pre></td></tr></table></figure>
<h4 id="2同时清理多个日志文件使用脚本文件"><a class="markdownIt-Anchor" href="#2同时清理多个日志文件使用脚本文件"></a> (2)同时清理多个日志文件[使用脚本文件]</h4>
<h5 id="1-文件rootlog_cleansh"><a class="markdownIt-Anchor" href="#1-文件rootlog_cleansh"></a> 1). 文件：<code>/root/log_clean.sh</code></h5>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/sh</span></span><br><span class="line"></span><br><span class="line">cat /dev/null &gt; /var/log/messages</span><br><span class="line">cat /dev/null &gt; /var/log/secure</span><br></pre></td></tr></table></figure>
<h5 id="2-定时任务"><a class="markdownIt-Anchor" href="#2-定时任务"></a> 2). 定时任务</h5>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 定时执行日志清理脚本</span></span><br><span class="line">* * * * * sh /root/log_clean.sh</span><br></pre></td></tr></table></figure>
<h3 id="3crontab-备份-source-code"><a class="markdownIt-Anchor" href="#3crontab-备份-source-code"></a> 3.crontab 备份 source code</h3>
<h4 id="1准备工作"><a class="markdownIt-Anchor" href="#1准备工作"></a> (1)准备工作</h4>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">backup -- 备份文件存放目录</span><br><span class="line">script -- 脚本文件目录</span><br><span class="line">www --- 网站根目录</span><br></pre></td></tr></table></figure>
<h4 id="2编写执行备份的脚本文件datascriptwww_backupsh"><a class="markdownIt-Anchor" href="#2编写执行备份的脚本文件datascriptwww_backupsh"></a> (2)编写执行备份的脚本文件[/data/script/www_backup.sh]</h4>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line"></span><br><span class="line">basedir = /data/backup</span><br><span class="line"></span><br><span class="line">www_src = $basedir/www_src/$(date +%F_%H%M)</span><br><span class="line"></span><br><span class="line">[ ! -d "$www_src" ]  &amp;&amp; mkdir -p $www_src</span><br><span class="line"></span><br><span class="line">cd /data</span><br><span class="line">tar -jpcf $www_src/www.tar.bz2 www</span><br></pre></td></tr></table></figure>
<h4 id="3脚本解释说明"><a class="markdownIt-Anchor" href="#3脚本解释说明"></a> (3)脚本解释说明</h4>
<h5 id="1-basedir-databackup"><a class="markdownIt-Anchor" href="#1-basedir-databackup"></a> 1). <code>basedir = /data/backup</code></h5>
<p>定义一个变量，名称为<code>basedir</code>，值为<code>/data/backup</code></p>
<h5 id="2-date-f_hm"><a class="markdownIt-Anchor" href="#2-date-f_hm"></a> 2). <code>$(date +%F_%H%M)</code></h5>
<p>获取系统的日期时间，并拼上日期(%F),再拼上小时(%H)和分钟(%M) =》 [2018-03-16_0715]</p>
<h5 id="3-www_src-basedirwww_srcdate-f_hm"><a class="markdownIt-Anchor" href="#3-www_src-basedirwww_srcdate-f_hm"></a> 3). <code>www_src = $basedir/www_src/$(date +%F_%H%M)</code></h5>
<p>使用变量 basedir 的值，再拼接出多层目录，赋值给 www_src[值为/data/backup/www_src/{当前日期时间的目录(动态)}]</p>
<h5 id="4-d-www_src"><a class="markdownIt-Anchor" href="#4-d-www_src"></a> 4). <code>[ ! -d &quot;$www_src&quot; ]</code></h5>
<p>相当于 if 的判断,判断$www_src 是否不是一个目录</p>
<h5 id="5-tar-jpcf-www_srcwwwtarbz2-www"><a class="markdownIt-Anchor" href="#5-tar-jpcf-www_srcwwwtarbz2-www"></a> 5). <code>tar -jpcf $www_src/www.tar.bz2 www</code></h5>
<p>打包/data/www 目录为 www.tar.bz2，并放置到$www_src 目录下[/data/backup/www_src/{当前日期时间的目录(动态)}/]</p>
<h4 id="4创建定时任务"><a class="markdownIt-Anchor" href="#4创建定时任务"></a> (4)创建定时任务</h4>
<p><code>* * * * * sh /data/script/www_backup.sh</code></p>
<h4 id="5重启定时任务使其生效"><a class="markdownIt-Anchor" href="#5重启定时任务使其生效"></a> (5)重启定时任务使其生效</h4>
<p><code>systemctl restart crond</code></p>
<h4 id="6查看备份文件大小被备份的原目录是-wordpress-系统"><a class="markdownIt-Anchor" href="#6查看备份文件大小被备份的原目录是-wordpress-系统"></a> (6)查看备份文件大小[被备份的原目录是 wordpress 系统]</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># /data/backup/www_src/2018-03-16_0715/</span></span><br><span class="line">8.4M    www.tar.bz2</span><br></pre></td></tr></table></figure>
<h3 id="4crontab-在-iptables-上的应用"><a class="markdownIt-Anchor" href="#4crontab-在-iptables-上的应用"></a> 4.crontab 在 iptables 上的应用</h3>
<h4 id="1应用场景"><a class="markdownIt-Anchor" href="#1应用场景"></a> (1)应用场景：</h4>
<p>DDOS 攻击或匿名暴力破解导致系统无法正常访问</p>
<h4 id="2解决之道"><a class="markdownIt-Anchor" href="#2解决之道"></a> (2)解决之道：</h4>
<p>使用 crontab 集成 iptables，实时监控系统的网络状态，及时将可疑的 ip 地址加入到网络黑名单</p>
<h4 id="3iptables-简介"><a class="markdownIt-Anchor" href="#3iptables-简介"></a> (3)iptables 简介：</h4>
<p>iptables 作为 Linux 下的内核防火墙，能够通过添加相应的规则，检测、修改、重定向、转发和丢弃 ip 数据包，从而过滤网络数据，实现保护系统网络的功能</p>
<p>CentOS7 默认使用 firewalld 服务维护内核防火墙，我们需要禁用 firewalld 服务，并安装 iptables 作为系统默认防火墙。</p>
<h4 id="4准备工作"><a class="markdownIt-Anchor" href="#4准备工作"></a> (4)准备工作</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 查看当前firewalld进程状态</span></span><br><span class="line">systemctl status firewalld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 关闭并禁用firewalld</span></span><br><span class="line">systemctl <span class="built_in">disable</span> firewalld</span><br><span class="line">systemctl stop firewalld</span><br><span class="line"></span><br><span class="line"><span class="comment"># 安装iptables服务</span></span><br><span class="line">yum install iptables-services</span><br><span class="line">[yes]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 开启iptables服务</span></span><br><span class="line">systemctl <span class="built_in">enable</span> iptables</span><br><span class="line"></span><br><span class="line"><span class="comment"># 启动iptables服务</span></span><br><span class="line">systemctl start iptables</span><br><span class="line"></span><br><span class="line"><span class="comment"># 验证iptables是否安装成功</span></span><br><span class="line">iptables -V</span><br></pre></td></tr></table></figure>
<h4 id="5设置网络访问黑名单文件datascriptblacklisttxt"><a class="markdownIt-Anchor" href="#5设置网络访问黑名单文件datascriptblacklisttxt"></a> (5)设置网络访问黑名单文件<a href="%E6%AF%8F%E4%B8%80%E8%A1%8C%E4%B8%BA%E4%B8%80%E4%B8%AAip%E5%9C%B0%E5%9D%80">/data/script/blacklist.txt</a></h4>
<h4 id="6脚本实现datascriptfirewallsh"><a class="markdownIt-Anchor" href="#6脚本实现datascriptfirewallsh"></a> (6)脚本实现[/data/script/firewall.sh]</h4>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#</span><span class="bash">!/bin/bash</span></span><br><span class="line"></span><br><span class="line">iptables -F</span><br><span class="line"></span><br><span class="line">list = /data/script/blacklist.txt</span><br><span class="line"></span><br><span class="line">for line in `cat $list`;do</span><br><span class="line">  iptables -I INPUT -s$line -j DROP</span><br><span class="line">  echo "$line is dropped into blacklist"</span><br><span class="line">done</span><br></pre></td></tr></table></figure>
<h4 id="7脚本解释说明"><a class="markdownIt-Anchor" href="#7脚本解释说明"></a> (7)脚本解释说明</h4>
<h5 id="1-iptables-f"><a class="markdownIt-Anchor" href="#1-iptables-f"></a> 1). <code>iptables -F</code></h5>
<p>清空 iptables 的所有记录</p>
<h5 id="2-for-line-in-cat-listdo"><a class="markdownIt-Anchor" href="#2-for-line-in-cat-listdo"></a> 2). for line in <code>cat $list</code>;do</h5>
<p>对/data/script/blacklist.txt 循环输出每一行</p>
<h5 id="3-iptables-i-input-sline-j-drop"><a class="markdownIt-Anchor" href="#3-iptables-i-input-sline-j-drop"></a> 3). <code>iptables -I INPUT -s$line -j DROP</code></h5>
<p>添加一个 input 链<br>
-s 相当于 source，将每一行的数据，传递给 iptables<br>
-j DROP 相当于一个 drop 操作，将当前主机接收到的数据包进行一个丢弃操作<br>
=》将 blacklist.txt 中的 ip 地址做一个拒绝访问的操作，使黑名单中的 ip 地址无法访问主机</p>
<h5 id="4-echo-line-is-dropped-into-blacklist"><a class="markdownIt-Anchor" href="#4-echo-line-is-dropped-into-blacklist"></a> 4). <code>echo &quot;$line is dropped into blacklist&quot;</code></h5>
<p>对每一行的 ip 地址拒绝访问后，输出一条信息提示</p>
<h4 id="8创建定时任务"><a class="markdownIt-Anchor" href="#8创建定时任务"></a> (8)创建定时任务</h4>
<p><code>* * * * * source /etc/profile; sh /data/script/firewall.sh</code></p>
<h4 id="9查看-iptables-拒绝访问主机的-ip-列表"><a class="markdownIt-Anchor" href="#9查看-iptables-拒绝访问主机的-ip-列表"></a> (9)查看 iptables 拒绝访问主机的 ip 列表</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">iptables -nvL</span><br></pre></td></tr></table></figure>
<h3 id="5crontab-在-jenkins-上的扩展"><a class="markdownIt-Anchor" href="#5crontab-在-jenkins-上的扩展"></a> 5.crontab 在 Jenkins 上的扩展</h3>
<h4 id="1jenkins-介绍"><a class="markdownIt-Anchor" href="#1jenkins-介绍"></a> (1)Jenkins 介绍</h4>
<pre><code>java编写的开源、持续、集成工具，最大优势就是将开发人员和运维人员完美的结合在一起。
</code></pre>
<h4 id="2使用前提"><a class="markdownIt-Anchor" href="#2使用前提"></a> (2)使用前提</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 安装</span></span><br><span class="line">yum install jenkins</span><br><span class="line">[y]</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看系统java路径</span></span><br><span class="line"><span class="built_in">which</span> java</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看系统java版本</span></span><br><span class="line">java -version</span><br></pre></td></tr></table></figure>
<blockquote>
<p>[jenkins 要求的最低版本要求配置&gt;1.8.0_111]</p>
</blockquote>
<h4 id="3编辑-jenkins-的启动配置文件etcinitdjenkins"><a class="markdownIt-Anchor" href="#3编辑-jenkins-的启动配置文件etcinitdjenkins"></a> (3)编辑 jenkins 的启动配置文件[/etc/init.d/jenkins]</h4>
<p>[=&gt;搜索 candidates 关键词]<br>
默认调用的 java 目录是/usr/bin/java 和/usr/lib/jvm/***/bin/java</p>
<p>添加 java 的路径<br>
<code>/usr/local/jdk1.8.0_111/bin/java</code></p>
<h4 id="4相关命令"><a class="markdownIt-Anchor" href="#4相关命令"></a> (4)相关命令</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">#启动jenkins服务</span></span><br><span class="line">systemctl start jenkins</span><br><span class="line"></span><br><span class="line"><span class="comment"># 查看jenkins服务是否正常启动，并查看jenkins服务是否打开8080端口监听服务</span></span><br><span class="line">lsof -i:8080</span><br></pre></td></tr></table></figure>
<h4 id="5在-web-网页中进行配置并使用-jenkins"><a class="markdownIt-Anchor" href="#5在-web-网页中进行配置并使用-jenkins"></a> (5)在 web 网页中进行配置并使用 jenkins</h4>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1.访问jenkins的后台地址</span></span><br><span class="line">10.110.16.5:8080</span><br><span class="line"></span><br><span class="line"><span class="comment"># 2.登录密码保存在系统的目录下</span></span><br><span class="line">/var/lib/jenkins/secrets/initialAdminPassword文件中</span><br><span class="line"></span><br><span class="line"><span class="comment"># 3.自定义jenkins=》安装插件</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 4.创建第一个管理员用户</span></span><br><span class="line"></span><br><span class="line"><span class="comment"># 5.创建新任务</span></span><br><span class="line">1)构建自由风格的软件项目</span><br><span class="line">2)构建触发器 =&gt; Build Periodically =&gt; 日程表[相当于crontab定时任务的时间表单] =&gt; * * * * *</span><br><span class="line">3)构建 =&gt; 增加构建步骤 =&gt; Execute shell =&gt; Command[执行定时任务时执行的操作] =&gt; <span class="built_in">echo</span> <span class="string">"this is a test build"</span></span><br></pre></td></tr></table></figure>
<p>【学习参考】：<a href="https://www.imooc.com/learn/1009" target="_blank" rel="noopener">慕课网-Crontab 不知疲倦的时间表</a></p>

		</div>

		
			<div class="art-item-footer">
					
						<span class="art-item-left"><i class="icon icon-chevron-thin-left"></i> <a href="/2018/07/07/web-goserver/" rel="prev" title="【Linux】网站上线">
							【Linux】网站上线
						</a>上一篇文章</span>
					
					
						<span class="art-item-right">下一篇文章：<a href="/2018/07/05/php-practice-wx-tp5-2/" rel="next"  title="微信小程序结合ThinkPHP5实战项目（二）-- 接口编写">
							微信小程序结合ThinkPHP5实战项目（二）-- 接口编写
						</a><i class="icon icon-chevron-thin-right"></i></span>
					
			</div>
		

		
			

    <div class="recommended_posts">
        <h3>推荐文章</h3>
        <ul>
            
                <li><a href="http://blog.i2arch.tech/2018/07/09/php-optimize/">PHP性能优化</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/07/07/web-goserver/">【Linux】网站上线</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/07/05/php-practice-wx-tp5-2/">微信小程序结合ThinkPHP5实战项目（二）-- 接口编写</a></li>
            
                <li><a href="http://blog.i2arch.tech/2018/07/05/http-ouath/">【PHP】第三方登录OAuth2.0</a></li>
            
        </ul>
    </div>


		
	</section>

	

</article>
<script>
	window.subData = {
		title: '【Linux】系统学习Crontab定时任务',
		tools: true
	}
</script>

      </div>

      <!-- 右侧边栏组件 -->
      <aside class='l_side'>
        
      </aside>

      <div class="gotop">
          
    <a href='javascript:void(0)'>
        <i class="icon icon-arrow_upward flat-box">
        </i>
    </a>

      </div>
      <script>setLoadingBarProgress(60);</script>
    </div>
  </div>
  <footer id="footer" class="clearfix">

	<div class="social-wrapper">
  	
      
        <a href="https://github.com/zqunor" class="social github"
          target="_blank" rel="external">
          <span class="icon icon-github"></span>
        </a>
      
        <a href="https://www.cnblogs.com/zqunor" class="social zhihu"
          target="_blank" rel="external">
          <span class="icon icon-zhihu"></span>
        </a>
      
        <a href="/atom.xml" class="social rss"
          target="_blank" rel="external">
          <span class="icon icon-rss"></span>
        </a>
      
    
  </div>
  <div>Theme <a href='https://github.com/stkevintan/hexo-theme-material-flow' class="codename">MaterialFlow</a>  Powered by<a href="https://blog.i2arch.tech/" target="_blank">程序小工</a>.</div>

</footer>

  <script>setLoadingBarProgress(80);</script>
  

    <script src="//apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src='//cdn.bootcss.com/node-waves/0.7.5/waves.min.js'></script>
    <script src="//cdn.bootcss.com/scrollReveal.js/3.3.2/scrollreveal.min.js"></script>
    <script src="/js/jquery.fitvids.js"></script>
      <script>
        var GOOGLE_CUSTOM_SEARCH_API_KEY = "";
        var GOOGLE_CUSTOM_SEARCH_ENGINE_ID = "";
        var ALGOLIA_API_KEY = "";
        var ALGOLIA_APP_ID = "";
        var ALGOLIA_INDEX_NAME = "";
        var AZURE_SERVICE_NAME = "";
        var AZURE_INDEX_NAME = "";
        var AZURE_QUERY_KEY = "";
        var BAIDU_API_ID = "fca5b83cf69f752ddc96a61ef64a3659";
        var SEARCH_SERVICE = "hexo";
        var ROOT = "/" || "/";
        if (!ROOT.endsWith('/')) ROOT += '/';
      </script>
      <script src="/js/search.js"></script>
        <script src="/js/app.js"></script>
  <script>setLoadingBarProgress(100);</script>
</body>
</html>
